<% add_decidim_page_title(t("page_topics", scope: "decidim.admin.titles")) %>

<div class="card" id="page_topics">
  <div class="item_show__header">
    <h1 class="item_show__header-title">
      <%= t("page_topics", scope: "decidim.admin.titles") %>
      <% if allowed_to? :create, :attachment_collection %>
        <%= link_to t("static_page_topics.new.create", scope: "decidim.admin"), [:new, :static_page_topic], class: "button button__sm button__secondary expanded small new" %>
      <% end %>
    </h1>
  </div>
  <% if topics.any? %>
    <div class="table-stacked">
      <table class="table-list">
        <thead>
          <tr>
            <th><%= t("activemodel.attributes.static_page_topic.name") %></th>
            <th><%= t("decidim.admin.actions.actions") %></th>
          </tr>
        </thead>
        <tbody>
          <% topics.each do |topic| %>
            <tr>
              <td data-label="<%= t("activemodel.attributes.static_page_topic.name") %>">
                <%= link_to translated_attribute(topic.title), [:edit, topic] %>
              </td>
              <td data-label="<%= t("decidim.admin.actions.actions") %>" class="table-list__actions">
                <button type="button" data-controller="dropdown" data-target="actions-topic-<%= topic.id %>" aria-label="<%= t("decidim.admin.actions.actions_label", resource: translated_attribute(topic.title)) %>">
                  <%= icon "more-fill", class: "text-secondary" %>
                </button>

                <div class="inline-block relative">
                  <ul id="actions-topic-<%= topic.id %>" class="dropdown dropdown__action" aria-hidden="true">
                    <% if allowed_to? :update, :static_page_topic, topic: topic %>
                      <li class="dropdown__item">
                        <%= link_to [:edit, topic], class: "dropdown__button" do %>
                          <%= icon "pencil-line" %>
                          <%= t("actions.edit", scope: "decidim.admin") %>
                        <% end %>
                      </li>

                      <hr>
                    <% end %>

                    <% if allowed_to? :destroy, :static_page_topic, topic: topic %>
                      <li class="dropdown__item">
                        <%= link_to topic, method: :delete, data: { confirm: t("actions.confirm_destroy", scope: "decidim.admin") }, class: "dropdown__button" do %>
                          <%= icon "delete-bin-line" %>
                          <%= t("actions.destroy", scope: "decidim.admin") %>
                        <% end %>
                      </li>
                    <% end %>
                  </ul>
                </div>
              </td>
            </tr>
          <% end %>
        </tbody>
      </table>
    </div>
  <% end %>
</div>
